<template>
  <div>
    <el-row>
      <el-col :span="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
      <el-col :span="8">
        <div class="grid-content bg-purple-light">
          欢迎回来，{{ data.name }}
          <el-descriptions title="我的信息">
            <el-descriptions-item label="用户名">
              {{ data.name }}
            </el-descriptions-item>
            <el-descriptions-item label="性别">
              {{ data.sex }}
            </el-descriptions-item>
            <el-descriptions-item label="公司名称">
              {{ data.cname }}
            </el-descriptions-item>
            <el-descriptions-item label="手机号">
              {{ data.phone }}
            </el-descriptions-item>
            <el-descriptions-item label="邮箱">
              {{ data.email }}
            </el-descriptions-item>
            <el-descriptions-item label="公司地址">
              {{ data.address }}
            </el-descriptions-item>
          </el-descriptions>
          <div>
            <!--点后弹出弹窗-->
            <el-form :inline="true">
              <el-form-item>
                <el-button type="primary" @click="dialog()">修改信息</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="grid-content bg-purple"></div>
      </el-col>
    </el-row>

    <!--弹出的弹窗内容-->
    <el-dialog title="编辑" :visible.sync="dialogVisible" center width="50%">
      <div
        style="
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
        "
      >
        <el-form :inline="true" ref="form" :model="form" label-width="100px">
          <el-form-item label="名字">
            <el-input v-model="form.name" placeholder="请输入名字"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-radio v-model="form.sex" label="男">男</el-radio>
            <el-radio v-model="form.sex" label="女">女</el-radio>
          </el-form-item>
          <el-form-item label="公司">
            <el-input
              v-model="form.cname"
              placeholder="请输入公司名字"
            ></el-input>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input
              v-model="form.phone"
              placeholder="请输入手机号"
            ></el-input>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
          </el-form-item>
          <el-form-item label="公司地址">
            <el-input
              v-model="form.address"
              placeholder="请输入公司地址"
            ></el-input>
          </el-form-item>
        </el-form>
        <!-- <p style="color: #f00">提示: 请输入你的个人信息</p> -->
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="edit(form)">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "ShouYe",
  data() {
    return {
      //弹出输入框
      dialogVisible: false,

      data: [],
      form: [],
    };
  },
  created() {
    this.companyInfo();
  },
  methods: {
    dialog() {
      this.dialogVisible = true; //显示弹窗
    },
    edit() {
      this.$axios.post("/companyEdit", this.form).then((res) => {
        console.log(res);
        this.$message({
          message: "操作成功",
          type: "success",
        });
      });
      console.log("调用了确认修改按钮");
      this.dialogVisible = false; //关闭弹窗
      //location.reload();
    },
    companyInfo() {
      const _this = this;
      const id = _this.$store.getters.getUser.id;
      //console.log(id)
      this.$axios.get("/company/" + id).then((res) => {
        const company = res.data.data;
        _this.data = res.data.data;
        _this.form = res.data.data;

        // 保存企业信息
        _this.$store.commit("SET_COMPANY", company);
      });
    },
  },
};
</script>

<style scoped>
</style>
